package Service;
import Bean.User;
import Dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired

import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    UserDao userDao;
    @Override
    public int register(User user) {
        //1.检查用户名是否存在
        User repeatUser = userDao.selectUserByUserName(user.getUsername());
        if (repeatUser != null){

            return 205;
        }
        //2.注册

        int i = userDao.insertUser(user);

        if (i != 1){
            return 502;
        }

        //3.注册成功 送积分

        return 200;
    }

    @Override
    public boolean login(String username, Integer password) {
        User user = userDao.selectUserByUserName(username);
        if (user != null && user.getPassword().equals(password)){
            return true;
            //登录成功

            //登录失败



            //用户名不存在
            //密码错误

        }
        return false;
    }
}
